package net.bolue.sysmng.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.bolue.console.model.BusiBase;
import net.bolue.sysmng.db.DbOpUtil;
import net.bolue.sysmng.exception.BolueException;
import net.bolue.sysmng.tblbean.DbopResMap;
import net.bolue.sysmng.tblbean.RepCnd;
import net.bolue.sysmng.tblbean.RepField;
import net.bolue.sysmng.tblbean.RepFunc;
import net.bolue.sysmng.tblbean.RepRes;
import net.bolue.web.report.RepConstants;

/**
 * 报表资源业务类
 * @author Administrator
 *
 */
public class ReportResModel extends BusiBase{
	
	public ReportResModel() {
		super();
	}

	public ReportResModel(HttpServletRequest request) {
		super(request);
	}

	/**
	 * 获得报表资源
	 * @param subSys	子系统
	 * @param repId		报表标识
	 * @return RepRes	报表资源
	 * @throws BolueException
	 */
	public RepRes getReport(String subSys, int repId) throws BolueException{
		String repResSql = "SELECT * FROM st_report WHERE SUBSYS='"+subSys+"' and REPID="+repId;
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		RepRes repRes = dbOpUtil.getOne(RepRes.class, repResSql, null);
		return repRes;
	}
	
	/**
	 * 获得报表数据列
	 * @param subSys	子系统
	 * @param repId		报表标识
	 * @return List		报表数据列
	 * @throws BolueException
	 */
	public List<RepField> getRepFieldList(String subSys, int repId) throws BolueException{
		String repFieldSql = "SELECT * FROM st_repfield WHERE SUBSYS='"+subSys+"' and REPID="+repId+" order by FIELDNO ASC";
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		List<RepField> fieldList = dbOpUtil.query(RepField.class, repFieldSql, null);
		return fieldList;
	}
	
	/**
	 * 获得报表条件
	 * @param subSys	子系统
	 * @param repId		报表标识
	 * @return List		报表条件
	 * @throws BolueException
	 */
	public List<RepCnd> getRepCndList(String subSys, int repId) throws BolueException{
		String cndListSql = "SELECT * FROM st_repcnd WHERE SUBSYS='"+subSys+"' and REPID="+repId+" order by CNDNO ASC";
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		List<RepCnd> cndList = dbOpUtil.query(RepCnd.class, cndListSql, null);
		return cndList;
	}
	
	/**
	 * 获得用户功能按钮
	 * @param subSys	子系统
	 * @param repId		报表标识
	 * @return List		功能按钮
	 * @throws BolueException
	 */
	public List<RepFunc> getUserRepFuncList(String subSys, int repId) throws BolueException{
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		String funcListSql = "SELECT * FROM st_repfunc WHERE SUBSYS='"+subSys+"' and REPID="+repId+" order by DISPNO ASC";
		List<RepFunc> funcList = dbOpUtil.query(RepFunc.class, funcListSql, null);
		return funcList;
	}
	
	/**
	 * 获得数据维护资源映射
	 * @param subSys
	 * @param repId
	 * @param dbopType
	 * @return
	 * @throws BolueException
	 */
	public DbopResMap getDBOpResMap(String subSys,Integer repId,Integer dbopType)throws BolueException{
		Map<String,Object> whereMap = new HashMap<String,Object>();
		whereMap.put("SUBSYS", subSys);
		whereMap.put("REPID", repId);
		whereMap.put("DBOPTYPE", dbopType);
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		DbopResMap dbopResMap = dbOpUtil.getOne(DbopResMap.class, "st_dbopresmap", null, whereMap);
		return dbopResMap;
	}
}
